/**
 * Created by IntelliJ IDEA.
 * User: Admin
 * Date: Jan 29, 2010
 * Time: 12:50:59 PM
 * To change this template use File | Settings | File Templates.
 */
package exttable;

import dbutils.DbUtils;
import utils.ELocale;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Locale;

public class SGTTestParametrs {
    private String userName;
    private String serverAddress;
    private Locale locale = new Locale("");
    private ELocale currentLocal = ELocale.RU;
    private String schemaDescRu;
    private String schemaDescEn;
    private String schemaDescKk;
    private boolean exceedLimits = false;
    private int userAccessLevel;

    private static SGTTestParametrs ourInstance = new SGTTestParametrs();

    public static SGTTestParametrs getInstance() {
        return ourInstance;
    }

    private SGTTestParametrs() {
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public Locale getLocale() {
        return locale;
    }

    public void setLocale(Locale locale) {
        this.locale = locale;
    }


    public static SGTTestParametrs getOurInstance() {
        return ourInstance;
    }

    public static void setOurInstance(SGTTestParametrs ourInstance) {
        SGTTestParametrs.ourInstance = ourInstance;
    }

    public ELocale getCurrentLocal() {
        return currentLocal;
    }

    public void setCurrentLocal(ELocale currentLocal) {
        this.currentLocal = currentLocal;
    }

    public String getServerAddress() {
        return serverAddress;
    }

    public void setServerAddress(String serverAddress) {
        this.serverAddress = serverAddress;
    }

    public boolean isExceedLimits() {
        return exceedLimits;
    }

    public void setExceedLimits(boolean exceedLimits) {
        this.exceedLimits = exceedLimits;
    }

    public String getSchemaDescRu() {
        return schemaDescRu;
    }

    public void setSchemaDescRu(String schemaDescRu) {
        this.schemaDescRu = schemaDescRu;
    }

    public String getSchemaDescEn() {
        return schemaDescEn;
    }

    public void setSchemaDescEn(String schemaDescEn) {
        this.schemaDescEn = schemaDescEn;
    }

    public String getSchemaDescKk() {
        return schemaDescKk;
    }

    public void setSchemaDescKk(String schemaDescKk) {
        this.schemaDescKk = schemaDescKk;
    }

    public int getUserAccessLevel() {
        return userAccessLevel;
    }

    public void setUserAccessLevel(int userAccessLevel) {
        this.userAccessLevel = userAccessLevel;
    }

    public static int getUserAccessLevelByUserName(String userName) {
        int userAccessLevel=0;
        try {
            Connection connection = DbUtils.getDBConnectionGeneral();
            PreparedStatement preparedStatement = connection.prepareStatement("SELECT access_level FROM login WHERE login=?");
            preparedStatement.setString(1, userName);
            System.out.println("ps :"+preparedStatement.toString());
            ResultSet resultSet=preparedStatement.executeQuery();
            while (resultSet.next()){
              userAccessLevel=resultSet.getInt("access_level");
            }
            connection.close();
            preparedStatement.close();
            resultSet.close();
            System.out.println("access_level: "+userAccessLevel);
            return userAccessLevel;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return userAccessLevel;
    }
}
